package com.example.finalwork2.service.impl;


import com.example.finalwork2.entity.VehicleSignal;
import com.example.finalwork2.handler.JudgeHandler;
import com.example.finalwork2.handler.OutputHandler;
import com.example.finalwork2.handler.SignalClassificationHandler;
import com.example.finalwork2.handler.SignalHandler;
import com.example.finalwork2.service.AlertService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AlertServiceImpl implements AlertService {
    private final SignalHandler head;

    @Autowired
    public AlertServiceImpl(
            JudgeHandler judgeHandler,
                            SignalClassificationHandler classificationHandler,
                            OutputHandler outputHandler) {
        // 手动组装责任链
        //receiveHandler.setNext(judgeHandler);
        judgeHandler.setNext(classificationHandler);
        classificationHandler.setNext(outputHandler);

        this.head = judgeHandler;
    }



    //责任链
    @Override
    public void processSignalMessage(VehicleSignal message) {
        head.handle(message);

    }
}
